﻿function takeSnap()
{
    //static map size

    var imgSize = new GSize(800, 800);
    snapShotControl.setMapSize(imgSize);

    var mapType = "";
    snapShotControl.setMapType(mapType);

    var mobile = false;
    snapShotControl.isMobile(mobile);

    var format = "jpeg";
    snapShotControl.setFormat(format);

    //      var usePolyline = true ;
    //      snapShotControl.usePolylineEncode(usePolyline);

    //snapShotControl.showPopup();

    var url = snapShotControl.getImage();
    //document.getElementById("snapshot_canvas").ImageUrl = url;
    document.getElementById("previewpic").setAttribute('src', url);
    $("#preview").dialog({ width: 600, height: 400, position: 'center', buttons: { "打印": function() { doPrint(); } } });
    //        var win = new Ext.Window({ title: "截图预览", autoScroll: true, width: 1020, height: 530, html: '" />
    //         win.show();
}

/**
*保存图片到数据库
*/
function SaveImgToDataSrc()
{
    alert("正在保存");
}

/**
* 打印用户的截图
*/
function PrintPic()
{
    alert("正在打印");
}

function doPrint()
{
    //               //打开一个新的窗体   
    //                var newWin = window.open('about:blank',"打印预览","");   
    //          //取得id为"order"的<div id="order"></div>之间的内容   
    //        //        var titleHTML = document.getElementById("map_canvas").innerHTML;   
    //        bdhtml=window.document.body.innerHTML;    
    //        sprnstr="<!--startprint-->";   
    //        eprnstr="<!--endprint-->";     
    //        prnhtml=bdhtml.substr(bdhtml.indexOf(sprnstr)+17);    
    //        prnhtml=prnhtml.substring(0,prnhtml.indexOf(eprnstr));    
    //        var titleHTML=prnhtml
    //                   //将取得的打印内容放入新窗体   
    //                newWin.document.write(titleHTML);   
    //                   //刷新新窗体   
    //                newWin.document.location.reload();   
    //              //调用打印功能     
    //                newWin.print();   
    //                   //打印完毕自动关闭新窗体   
    //                newWin.close();   
    // PageSetup_Null();
    bdhtml = window.document.body.innerHTML;
    sprnstr = "<!--startprint-->";
    eprnstr = "<!--endprint-->";
    prnhtml = bdhtml.substr(bdhtml.indexOf(sprnstr) + 17);
    prnhtml = prnhtml.substring(0, prnhtml.indexOf(eprnstr));
    var newWin = window.open('about:blank', "打印预览", "");
    newWin.document.write(prnhtml);
    newWin.document.location.reload();
    newWin.document.body.innerHTML = prnhtml;
    newWin.print();
    newWin.close();
}


//设置网页打印的页眉页脚为空
function PageSetup_Null()
{
    var HKEY_Root, HKEY_Path, HKEY_Key;
    HKEY_Root = "HKEY_CURRENT_USER";
    HKEY_Path = "\\Software\\Microsoft\\Internet Explorer\\PageSetup\\";

    try
    {
        var Wsh = new ActiveXObject("WScript.Shell");
        HKEY_Key = "header";
        Wsh.RegWrite(HKEY_Root + HKEY_Path + HKEY_Key, "");
        HKEY_Key = "footer";
        Wsh.RegWrite(HKEY_Root + HKEY_Path + HKEY_Key, "");
    }
    catch (e) { }
}
